package com.zfs.test.controller;

import java.util.Arrays;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zfs.test.pojo.Xinxi;
import com.zfs.test.service.XinxiService;

@RestController
@CrossOrigin
@RequestMapping("/xinxi")
public class XinxiController {

	@Autowired
	private XinxiService xs;
	
	@GetMapping("/showall")
	public Map<String,Object> showAll(String dname,int page,int limit){
		return xs.showAll(dname,page,limit);
	}
	
	@DeleteMapping("/delete/{did}")
	public int delete(@PathVariable("did") String did){
		System.out.println(did);
		return xs.delete(did);
	}
	
	@DeleteMapping("/deleteall/{did}")
	public int deleteall(@PathVariable("did") String[] did){
		int h=0;
		for (String str : did) {
			
			h=xs.delete(str);
			
		}
		return h;
	}
	
	@PostMapping("/insert")
	public int insert(Xinxi x){
		return xs.insert(x);
	}
	
	@PostMapping("/update")
	public int update(Xinxi x){
		return xs.update(x);
	}
	
}
